package com.oren.proxy;

import com.oren.annotation.WswAspect;
import com.oren.annotation.WswController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;

/**
 * @author wangshiwei
 * @create 2018/7/7 17:18
 * @desc 拦截所有的controller的方法
 **/
@WswAspect(WswController.class)
public class ControllerProxy  extends AspectProxy{

    private  static final Logger LOGGER= LoggerFactory.getLogger(ControllerProxy.class);

    private Long begin;

    @Override
    public void before(Class<?> cls, Method method, Object[] params) throws Throwable {
        //super.before(cls, method, params);
        LOGGER.debug("------切面begin开始------");
        LOGGER.debug(String.format("class : %s",cls.getName()));
        LOGGER.debug(String.format("method : %s",method.getName()));
        begin=System.currentTimeMillis();
    }

    @Override
    public void after(Class<?> cls, Method method, Object[] params, Object result) throws Throwable {
        //super.after(cls, method, params, result);
        LOGGER.debug(String.format("time : %dms",System.currentTimeMillis()-begin));
        LOGGER.debug("------切面end---------");

    }
}
